added SSCLI 1.0
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / CppShellExtThumbnailHandler / ClassFactory.cpp
blobb3599cbe614aee2581cf95b2a663906957e3a1e0
1 /****************************** Module Header ******************************\
2 Module Name: ClassFactory.cpp
3 Project: CppShellExtThumbnailHandler
4 Copyright (c) Microsoft Corporation.
6 The file implements the class factory for the RecipeThumbnailProvider COM class.
8 This source is subject to the Microsoft Public License.
9 See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
10 All other rights reserved.
12 THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
13 EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
14 WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
15 \***************************************************************************/
17 #include "ClassFactory.h"
18 #include "RecipeThumbnailProvider.h"
19 #include <new>
22 extern long g_cDllRef;
25 ClassFactory::ClassFactory() : m_cRef(1)
27 InterlockedIncrement(&g_cDllRef);
30 ClassFactory::~ClassFactory()
32 InterlockedDecrement(&g_cDllRef);
37 // IUnknown
40 IFACEMETHODIMP ClassFactory::QueryInterface(REFIID riid, void **ppv)
42 HRESULT hr = S_OK;
44 if (IsEqualIID(IID_IUnknown, riid) ||
45 IsEqualIID(IID_IClassFactory, riid))
47 *ppv = static_cast<IUnknown *>(this);
48 AddRef();
50 else
52 hr = E_NOINTERFACE;
53 *ppv = NULL;
56 return hr;
59 IFACEMETHODIMP_(ULONG) ClassFactory::AddRef()
61 return InterlockedIncrement(&m_cRef);
64 IFACEMETHODIMP_(ULONG) ClassFactory::Release()
66 ULONG cRef = InterlockedDecrement(&m_cRef);
67 if (0 == cRef)
69 delete this;
71 return cRef;
75 //
76 // IClassFactory
79 IFACEMETHODIMP ClassFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv)
81 HRESULT hr = CLASS_E_NOAGGREGATION;
83 // pUnkOuter is used for aggregation. We do not support it in the sample.
84 if (pUnkOuter == NULL)
86 hr = E_OUTOFMEMORY;
88 // Create the COM component.
89 RecipeThumbnailProvider *pExt = new (std::nothrow) RecipeThumbnailProvider();
90 if (pExt)
92 // Query the specified interface.
93 hr = pExt->QueryInterface(riid, ppv);
94 pExt->Release();
98 return hr;
101 IFACEMETHODIMP ClassFactory::LockServer(BOOL fLock)
103 if (fLock)
105 InterlockedIncrement(&g_cDllRef);
107 else
109 InterlockedDecrement(&g_cDllRef);
111 return S_OK;